using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using Afrs.Draco.Prms.Client.Proxy;
using Afrs.Prms.DataObject;

namespace 
{
  /// <summary>
  /// Users Test Class
  /// </summary>
  [TestClass]
  public class TestUsers
  {
    #region Class Variables
    private CdoPrms<DOUsers>		m_Users;
    private CdoPrmsList<DOUsers>	m_AllUsers;
    #endregion

    #region Class Constructors & Destructors
    /// <summary>
    /// Constructs the test
    /// </summary>
    public TestUsers()
    {
      // Create the data objects
      this.m_Users	= new CdoPrms<DOUsers>();
      this.m_AllUsers	= new CdoPrmsList<DOUsers>();
    }
    #endregion

    #region Class Methods
    /// <summary>
    /// Retrieves all Users data objects
    /// </summary>
    [TestMethod]
    public void UsersRetrieveAll()
    {
      // Set up the data object for list retrieval
      this.m_AllUsers.DataObject = new DOUsers();
      this.m_AllUsers.ListAction = AfrsDOListAction.Retrieve;

      // Perform the action and determine the success
      if (!this.m_AllUsers.PerformAction())
      {
        // Assert the errors
        if (this.m_AllUsers.Errors.Count > 0) { Assert.Fail(this.m_AllUsers.Errors[0].Message); }
        else { Assert.Fail("Unknown error occurred"); }
      }

      // Return to calling method
      return;
    }

    /// <summary>
    /// Create a new Users
    /// </summary>
    [TestMethod]
    public void UsersCreate()
    {
      // Set up the data object for creation
      this.m_Users.DataObject.UserLogon = "Test UserLogon";
      this.m_Users.DataObject.UserPassword = "Test UserPassword";
      this.m_Users.DataObject.FirstName = "Test FirstName";
      this.m_Users.DataObject.Surname = "Test Surname";
      this.m_Users.DataObject.Extention = "Test Extention";
      this.m_Users.DataObject.Telephone = "Test Telephone";
      this.m_Users.DataObject.Cellphone = "Test Cellphone";
      this.m_Users.DataObject.Email = "Test Email";
      this.m_Users.DataObject.DivisionName = "Test DivisionName";
      this.m_Users.DataObject.DepartmentName = "Test DepartmentName";
      this.m_Users.DataObject.Access = "Test Access";
      this.m_Users.DataObject.Active = false;
      this.m_Users.DataObject.Action = AfrsDataObjectAction.Create;

      // Perform the action and determine the success
      if (!this.m_Users.PerformAction())
      {
        // Assert the errors
        if (this.m_Users.Errors.Count > 0) { Assert.Fail(this.m_Users.Errors[0].Message); }
        else { Assert.Fail("Unknown error occurred"); }
      }

      // Return to calling method
      return;
    }

    /// <summary>
    /// Retrieves a specific Users
    /// </summary>
    [TestMethod]
    public void UsersRetrieve()
    {
      // Determine whether the data object needs to be specified
      if (this.m_Users.DataObject.Id == 0)
      {
        // Specify the data object to retrieve
        this.m_Users.DataObject.UserId = 12.3F;
      }

      // Set up the data object action for retrieval
      this.m_Users.DataObject.Action = AfrsDataObjectAction.Retrieve;

      // Perform the action and determine the success
      if (!this.m_Users.PerformAction())
      {
        // Assert the errors
        if (this.m_Users.Errors.Count > 0) { Assert.Fail(this.m_Users.Errors[0].Message); }
        else { Assert.Fail("Unknown error occurred"); }
      }

      // Return to calling method
      return;
    }
    #endregion
  }
}
